package com.huiquan.foundation.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huiquan.answer.service.AnswerService;
import com.huiquan.dyad.domain.DyadPre;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huiquan.analysis.constants.AnalysisSentenceConstant;
import com.huiquan.analysis.job.AnalysisInit;
import com.huiquan.analysis.job.AnalysisSortJob;
import com.huiquan.analysis.service.AnalysisDictionaryService;
import com.huiquan.analysis.service.AnalysisOutsourcingService;
import com.huiquan.analysis.service.AnalysisSentenceService;
import com.huiquan.dyad.service.DyadInitService;
import com.huiquan.foundation.job.JobManager;
import com.huiquan.foundation.service.SubpackageService;
import com.huiquan.framework.base.ReturnData;
import com.huiquan.framework.utils.RequestParamUtil;
import com.huiquan.framework.utils.ReturnUtil;
import com.huiquan.icd.job.IcdDiseaseJob;
import com.huiquan.icd.service.IcdDiseaseExternalService;
import com.huiquan.icd.service.IcdDiseaseIndexService;
import com.huiquan.icd.service.IcdDiseaseService;
import com.huiquan.icd.service.IcdDiseaseSymptomService;
import com.huiquan.management.constant.GradeContants;
import com.huiquan.symptom.job.SymptomJob;
import com.huiquan.vocab.job.DyadJob;
import com.huiquan.vocab.service.VocabDyadInitService;

@Controller
public class TestController {

	protected final Logger LOGGER = LoggerFactory.getLogger(getClass());

	@Autowired
	private IcdDiseaseIndexService icdDiseaseIndexService;
	@Autowired
	private IcdDiseaseJob icdDiseaseJob;
	@Autowired
	private AnalysisInit initSentenceJob;
	@Autowired
	private AnalysisSortJob sentenceSortJob;
	@Autowired
	private JobManager jobManager;
	@Autowired
	private DyadJob dyadJob;
	@Autowired
	private AnalysisSentenceService sentenceService;
	@Autowired
	private SymptomJob symptomJob;
	@Autowired
	private AnalysisDictionaryService analysisDictionaryService;
	@Autowired
	private IcdDiseaseSymptomService icdDiseaseSymptomService;
	@Autowired
	private IcdDiseaseService icdDiseaseService;
	@Autowired
	private IcdDiseaseExternalService icdDiseaseExternalService;
	@Autowired
	private SubpackageService subpackageService;
	@Autowired
	private VocabDyadInitService vocabDyadInitService;
	@Autowired
	private AnalysisInit analysisInitJob;
	@Autowired
	private AnalysisOutsourcingService analysisOutsourcingService;
	@Autowired
	private DyadInitService dyadInitService;
	@Autowired
	private AnswerService answerService;

	/**
	 * 功能测试 类型type：initzs-；sortzs-；
	 */
	@ResponseBody
	@RequestMapping(value = "/functionTest.do")
	public ReturnData functionTest(HttpServletRequest req, HttpServletResponse resp) throws Exception {

		String type = RequestParamUtil.getTrimString(req, "type");
		String secondType = RequestParamUtil.getTrimString(req, "secondType");

		if (type != null) {
			switch (type) {
			case "runningData":
				jobManager.synchronizeData();
				jobManager.initData();
				break;
			case "synchronizeData":
				jobManager.synchronizeData();
				break;
			case "initzs":
				initSentenceJob.initZs();
				break;
			case "sortzs":
				sentenceSortJob.sortZs();
				break;
			case "mh":
				jobManager.migrate();
				break;
			case "initdiin":
				icdDiseaseJob.initDiseaseInspection();
				break;
			case "submitdiin":
				icdDiseaseIndexService.submitServer();
				break;
			case "updateRedis":
				sentenceService.updateRedisDataByDB();
				break;
			case "updateSphinxIndex":
				jobManager.updateSphinxIndexForTest();
				break;
			case "initXbsData":
//				initSentenceJob.initXbsData();
				break;
			case "initXbs":
				initSentenceJob.initXbs();
				break;
			case "initXbs2":
				initSentenceJob.initXbs(secondType);
				break;
			case "checkData":
				jobManager.checkData();
				break;
			case "importSymptomRevealSynonym":
				symptomJob.importSymptomRevealSynonym();
				break;
			case "generateDyadRule2File":
				dyadJob.generateDyadRule2File();
				break;
			case "initTimeDictionary":
				analysisDictionaryService.initTimeDictionary();
				break;
			case "symptomInitOrder":
				icdDiseaseSymptomService.initOrderOSymptom();
				break;
			case "runDisease":
				jobManager.runDisease();
				break;
			case "diseaseSectionRepository":
				icdDiseaseJob.generateDiseaseSectionRepository();
				break;
			case "initAge":
				icdDiseaseService.initSexAge();
				break;
			case "initRevealStdCurrent":
				symptomJob.initRevealStdCurrent();
				break;
			case "initExternal":
				icdDiseaseExternalService.initExternalData();
				break;
			case "initInspectionChecked":
				icdDiseaseJob.initDiseaseInspectionChecked();
				break;
			case "getSidListToUser":
				String uid = req.getParameter("uid");
				List<Long> sidList = subpackageService.getSidListToUser(
						AnalysisSentenceConstant.XBS_SOURCE_TYPE_IMAGEOLOGY_INFO, Long.parseLong(uid));
				Map<String, Object> data = new HashMap<>();
				data.put("sidList", sidList);
				return ReturnUtil.success(data);
			case "checkUserCommit":
				String sid = req.getParameter("sid");
				subpackageService.checkUserCommit(Long.parseLong(sid));
				break;
			case "initSubpackage":
				// 预标注结束后初始化分包数据
				subpackageService.doInitSubpackage(GradeContants.TYPE_ANALYSIS_XBS_IMAGEOLOGY, null);
				break;
			case "init7":
				vocabDyadInitService.init7();
				break;
			case "initct":
				analysisInitJob.initXbsDataWithSecondType(AnalysisSentenceConstant.XBS_SOURCE_TYPE_IMAGEOLOGY_INFO);
				break;
			case "initNotExistsVocabulary":
				analysisOutsourcingService.initSentence();
				break;
			case "initLabelSentence":
				analysisOutsourcingService.initLabelSentence();
				break;
			case "preInit":
				jobManager.preInit();
				break;
			case "initFlag":
				dyadInitService.initFlag();
				break;
			case "initPageByOrderVocab":
				dyadInitService.initPageByOrderVocab();
				break;
			case "initDyadPre":
				dyadInitService.initDyadPre();;
				break;
			case "updateAnswerData":
				answerService.updateAnswerData();
				break;
			case "newDyadInit":
				dyadInitService.init();
				break;
			case "initDataByPatternBatch":
				jobManager.initDataByPatternBatch();
				break;
			case "testInitDyad":
				List<DyadPre > s = dyadInitService.getDyadPreBySymptom(",右,手,第1,指,骨,酸痛,",",p,o,p,oa,oa,s,");
				break;
			default:
				break;
			}
		}
		return ReturnUtil.success();
	}
}
